/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#include "log.h"
#include "dxvertexbuffer.h"

namespace Engine
{
	/**********************************************************************************************************/
	DXVertexBuffer::DXVertexBuffer(IDirect3DVertexBuffer9* vertexBuffer)
		:m_vertexBuffer(vertexBuffer)
	{
	}
	/**********************************************************************************************************/
	DXVertexBuffer::~DXVertexBuffer()
	{
		Log::GetSingleton() << "DXVertexBuffer deleted" << std::endl;
	}
	/**********************************************************************************************************/
	void* DXVertexBuffer::Lock()
	{
		void *pData = 0;
		if(FAILED(m_vertexBuffer->Lock(0,0,&pData,0)))
			throw std::logic_error("Can't lock dx vertex buffer");
		return pData;
	}
	/**********************************************************************************************************/
	const void* DXVertexBuffer::Lock() const
	{
		void *pData = 0;
		if(FAILED(m_vertexBuffer->Lock(0,0,&pData,0)))
			throw std::logic_error("Can't lock dx vertex buffer");
		return pData;
	}
	/**********************************************************************************************************/
	void DXVertexBuffer::UnLock()const
	{
		if(FAILED(m_vertexBuffer->Unlock()))
			throw std::logic_error("Can't unlock dx vertex buffer");
	}
	/**********************************************************************************************************/
	IDirect3DVertexBuffer9* DXVertexBuffer::GetBuffer()
	{
		return m_vertexBuffer.GetPointer();
	}
	/**********************************************************************************************************/
}
